package com.juyu.miliao.api.controller.activity;

import com.alibaba.fastjson.JSONObject;
import com.juyu.miliao.api.domain.vo.ActivityRewardLogVO;
import com.juyu.miliao.api.domain.vo.SanGuoActivitiesRankingResultVO;
import com.juyu.miliao.api.service.Activity.SanGuoGameActivityService;
import com.juyu.miliao.common.domain.Subject;
import org.springframework.security.core.Authentication;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.List;

/**
 *  暑假活动之游戏人间
 * @Auther: 卜加超
 * @Date: 2019/8/6 17:56
 * @Description:
 */
@RestController
@RequestMapping("/sanGuoGameActivity")
public class SanGuoGameActivityController {
    @Resource
    private SanGuoGameActivityService sanGuoGameActivityService;

    /**
     * 暑期活动之寻寻三国奖励列表
     * 和 个人当天盈利的寻豆数
     * @param token
     * @return
     */
    @GetMapping("/list")
    public JSONObject getActiveGameRewardList(Authentication token){
        Subject subject = (Subject) token.getPrincipal();
       return sanGuoGameActivityService.getSanGuoGameActivityList(subject.getId());
    }

    /**
     * 领取三国奖励
     */
    @PostMapping("/sanGuoRewards")
    public void getSanGuoRewards(Authentication token,int sanGuoActiveId){
        Subject subject = (Subject) token.getPrincipal();
        sanGuoGameActivityService.getSanGuoRewards(subject.getId(),sanGuoActiveId);
    }
    /**
     * 领取三国奖励日志
     */
    @GetMapping("/sanGuoLog/{page}-{pageSize}")
    public List<ActivityRewardLogVO> getRewardsLog(Authentication token, @PathVariable("page") Integer page,
                                                   @PathVariable("pageSize") Integer pageSize) {

        if (page <= 0) {
            page = 1;
        }
        if (pageSize <= 0) {
            pageSize = 20;
        }
        Subject subject = (Subject) token.getPrincipal();
        return sanGuoGameActivityService.getSanGuoRewardsLog(subject.getId(), 2,page,pageSize);
    }
    /**
     * 三国奖励排行榜
     * @param token
     * @return
     */
    @GetMapping("/sanGuoRanking")
    public SanGuoActivitiesRankingResultVO getSanGuoRankingList(Authentication token){
        Subject subject = (Subject) token.getPrincipal();
     return sanGuoGameActivityService.getSanGuoRankingList(subject.getId());
    }


}
